package com.tz.service.impl;

import com.tz.entity.Research;
import com.tz.mapper.ResearchsMapper;
import com.tz.service.ResearchsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 于大海 on 2018/1/3.
 */
@Service
public class ResearchsServiceImpl implements ResearchsService {
    @Autowired
    ResearchsMapper researchsMapper;

    @Override
    public Map<String, List<Research>> findMonth(String monthData) {

        Map<String, List<Research>> map = new HashMap<>();
        List<Research> list = researchsMapper.selectMonth(monthData);
        for (Research e : list) {
            if (map.containsKey(e.getUser().getUsername())) {

                map.get(e.getUser().getUsername()).add(e);
            } else {
                List<Research> researchs = new ArrayList<>();
                researchs.add(e);
                map.put(e.getUser().getUsername(), researchs);
            }

        }
        return map;
    }

    @Override
    public Map<String, List<Research>> findQuarter(String startData, String endDate) {
        Map<String, List<Research>> map = new HashMap<>();
        List<Research> list = researchsMapper.selectQuarter(startData, endDate);
        for (Research e : list) {
            if (map.containsKey(e.getUser().getUsername())) {

                map.get(e.getUser().getUsername()).add(e);
            } else {
                List<Research> researchs = new ArrayList<>();
                researchs.add(e);
                map.put(e.getUser().getUsername(), researchs);
            }

        }
        return map;
    }

    @Override
    public Map<String, List<Research>> findYear(String yearData) {
        Map<String, List<Research>> map = new HashMap<>();
        List<Research> list = researchsMapper.selectYear(yearData);

       for (Research e : list) {
            if (map.containsKey(e.getUser().getUsername())) {

                map.get(e.getUser().getUsername()).add(e);
            } else {
                List<Research> researchs = new ArrayList<>();
                researchs.add(e);
                map.put(e.getUser().getUsername(), researchs);

            }}
        return map;
    }


}
